/*
 * port.h
 *
 *  Created on: Nov 2, 2013
 */

#ifndef PORT_H_
#define PORT_H_
#include "derivative.h"

#if defined(MCU_MKL25Z4)

#define RGB_Red_shift		(1<<18)
#define RGB_Green_shift		(1<<19)
#define RGB_Blue_shift		(1<<1)

#define PORT__nRedLED_PCR	PORTB_PCR18
#define PORT__nGreenLED_PCR	PORTB_PCR19
#define PORT__nBlueLED_PCR	PORTD_PCR1

#define PORT__nRedLED_DDR	GPIOB_PDDR
#define PORT__nGreenLED_DDR	GPIOB_PDDR
#define PORT__nBlueLED_DDR	GPIOD_PDDR

#define PORT__nUART_TXD_PCR	PORTA_PCR2
#define PORT__nUART_RXD_PCR	PORTA_PCR1

#define RGB_Red_ON   		(GPIOB_PCOR = RGB_Red_shift)
#define RGB_Red_OFF			(GPIOB_PSOR = RGB_Red_shift)
#define RGB_Red_TOOGLE		(GPIOB_PTOR = RGB_Red_shift)

#define RGB_Green_ON   		(GPIOB_PCOR = RGB_Green_shift)
#define RGB_Green_OFF		(GPIOB_PSOR = RGB_Green_shift)
#define RGB_Green_TOOGLE	(GPIOB_PTOR = RGB_Green_shift)

#define RGB_Blue_ON   		(GPIOD_PCOR = RGB_Blue_shift)
#define RGB_Blue_OFF		(GPIOD_PSOR = RGB_Blue_shift)
#define RGB_Blue_TOOGLE		(GPIOD_PTOR = RGB_Blue_shift)

#elif defined(MCU_MKL02Z4)
/******************************************************************************
* GENERAL PORT MODULE CONFIGURATIONS 
******************************************************************************/
#define USE_IRQ_PORTA    True 

#define USE_IRQ_PTA0     False
#define USE_IRQ_PTA1     False
#define USE_IRQ_PTA7     False
#define USE_IRQ_PTA10    False
#define USE_IRQ_PTA11    True
#define USE_IRQ_PTA12    False

#if (USE_IRQ_PTA0 == True)
/**
 * Description: Adaptation name for IRQA0 interrupt application
 * handler function.
 */
#define PORT__vIRQPTA0()
/**
 * Description: Macro definitions to handle Flag interrupt. 
 */
#define PORT__nShiftPTA0        (0u)
#define PORT__nflagPTA0         (0x01 & ((uint8) (PORTA_ISFR >> PORT__nShiftPTA0)))
#define PORT__nClearflagPTA0    PORTA_ISFR |= (0x01 << PORT__nShiftPTA0)
#endif 

#if (USE_IRQ_PTA1 == True)
/**
 * Description: Adaptation name for IRQA1 interrupt application
 * handler function.
 */
#define PORT__vIRQPTA1()
/**
 * Description: Macro definitions to handle Flag interrupt. 
 */
#define PORT__nShiftPTA1        (1u)
#define PORT__nflagPTA1         (0x01 & ((uint8) (PORTA_ISFR >> PORT__nShiftPTA1)))
#define PORT__nClearflagPTA1    PORTA_ISFR |= (0x01 << PORT__nShiftPTA1)
#endif 

#if (USE_IRQ_PTA7 == True)
/**
 * Description: Adaptation name for IRQA7 interrupt application
 * handler function.
 */
#define PORT__vIRQPTA7()
/**
 * Description: Macro definitions to handle Flag interrupt. 
 */
#define PORT__nShiftPTA7        (7u)
#define PORT__nflagPTA7         (0x01 & ((uint8) (PORTA_ISFR >> PORT__nShiftPTA7)))
#define PORT__nClearflagPTA7    PORTA_ISFR |= (0x01 << PORT__nShiftPTA7)
#endif 

#if (USE_IRQ_PTA10 == True)
/**
 * Description: Adaptation name for IRQA10 interrupt application
 * handler function.
 */
#define PORT__vIRQPTA10()
/**
 * Description: Macro definitions to handle Flag interrupt. 
 */
#define PORT__nShiftPTA10        (10u)
#define PORT__nflagPTA10         (0x01 & ((uint8) (PORTA_ISFR >> PORT__nShiftPTA10)))
#define PORT__nClearflagPTA10    PORTA_ISFR |= (0x01 << PORT__nShiftPTA10)
#endif 

#if (USE_IRQ_PTA11 == True)
/**
 * Description: Adaptation name for IRQA11 interrupt application
 * handler function.
 */
#define PORT__vIRQPTA11()        MPR_vInterruptELERead()
/**
 * Description: Macro definitions to handle Flag interrupt. 
 */
#define PORT__nShiftPTA11        (11u)
#define PORT__nflagPTA11         (0x01 & ((uint8) (PORTA_ISFR >> PORT__nShiftPTA11)))
#define PORT__nClearflagPTA11    PORTA_ISFR |= (0x01 << PORT__nShiftPTA11)
#endif 

#if (USE_IRQ_PTA12 == True)
/**
 * Description: Adaptation name for IRQA12 interrupt application
 * handler function.
 */
#define PORT__vIRQPTA12()
/**
 * Description: Macro definitions to handle Flag interrupt. 
 */
#define PORT__nShiftPTA12        (12u)
#define PORT__nflagPTA12         (0x01 & ((uint8) (PORTA_ISFR >> PORT__nShiftPTA12)))
#define PORT__nClearflagPTA12    PORTA_ISFR |= (0x01 << PORT__nShiftPTA12)
#endif 



//#define USE_IRQ_PORTB
/******************************************************************************
* RGB LED SECTION
******************************************************************************/

#define RGB_Red_shift		      (1<<6)
#define RGB_Green_shift		      (1<<7)
#define RGB_Blue_shift		      (1<<10)

#define PORT__nRedLED_PCR        PORTB_PCR6
#define PORT__nGreenLED_PCR      PORTB_PCR7
#define PORT__nBlueLED_PCR       PORTB_PCR10

#define PORT__nRedLED_DDR        GPIOB_PDDR
#define PORT__nGreenLED_DDR      GPIOB_PDDR
#define PORT__nBlueLED_DDR       GPIOB_PDDR

#define RGB_Red_ON         (GPIOB_PCOR = RGB_Red_shift)
#define RGB_Red_OFF        (GPIOB_PSOR = RGB_Red_shift)
#define RGB_Red_TOOGLE     (GPIOB_PTOR = RGB_Red_shift)

#define RGB_Green_ON       (GPIOB_PCOR = RGB_Green_shift)
#define RGB_Green_OFF      (GPIOB_PSOR = RGB_Green_shift)
#define RGB_Green_TOOGLE   (GPIOB_PTOR = RGB_Green_shift)

#define RGB_Blue_ON        (GPIOB_PCOR = RGB_Blue_shift)
#define RGB_Blue_OFF       (GPIOB_PSOR = RGB_Blue_shift)
#define RGB_Blue_TOOGLE    (GPIOB_PTOR = RGB_Blue_shift)

/******************************************************************************
* TOUCH CONTROLLER SECTION
******************************************************************************/
#define PORT__IRQpin_shift       (1<<11)
/* PORTx registers */
#define PORT__nIRQpin_PCR        PORTA_PCR11
#define PORT__nIRQpin_GPCLR      PORTA_GPCLR
#define PORT__nIRQpin_GPCHR      PORTA_GPCHR
#define PORT__nIRQpin_ISFR       PORTA_ISFR
/* GPIO registers */
#define PORT__nIRQpin_DDR        GPIOA_PDDR
/******************************************************************************
* UART SECTION
******************************************************************************/
#define PORT__nUART_TXD_PCR	   PORTB_PCR1
#define PORT__nUART_RXD_PCR	   PORTB_PCR2



#else
#error "Unknown configuration board"
#endif 



void PORT_vPinMuxInit(void);
void PORT_vDataDirectionInit(void);
void PORT_vOutputInit(void);

#endif /* PORT_H_ */
